import matplotlib.pyplot as plt
import numpy as np

from rootPath import project_path

species = ("MR", "MR+RD+EE", "MR+WR+EE", "MR+RD+ET", "MR+WR+ET")
penguin_means = {
    'Client1': (31.37, 30.68, 30.77, 37.59, 36.68),
    'Client2': (31.33, 30.71, 30.73, 37.73, 36.62),
    'Client3': (15.14, 15.33, 15.60, 10.89, 10.97),
    'Client4': (14.71, 14.62, 14.87, 9.82, 10.90),
    'Client5': (7.45, 8.46, 8.03, 3.96, 4.82),
}

x = np.arange(len(species))  # the label locations
width = 0.10  # the width of the bars
multiplier = 0

fig, ax = plt.subplots(figsize=(12, 6), layout='constrained')

for attribute, measurement in penguin_means.items():
    offset = width * multiplier
    rects = ax.bar(x + offset, measurement, width, label=attribute)
    # ax.bar_label(rects, padding=3, fontsize=6)  # 设置字体大小为12
    multiplier += 1


size = 20
ax.set_ylabel('contribution percentage', fontsize=size)
# ax.set_xticks(x + width, species,fontsize=15)
ax.tick_params(axis='y', labelsize=size)
ax.set_xticks(x + width * (len(penguin_means) - 1) / 2, species, fontsize=size)
ax.legend(loc='upper left', ncols=3, fontsize=size)
ax.set_ylim(0, 45)

# 保存图形到文件，确保文件名包含 .png 扩展名
plt.savefig(project_path + '/experiment/imgs/contributions_nlss.png', dpi=300, bbox_inches='tight')
plt.show()